<?php
/**
 * 文章
 *
 */
defined('InShopNC') or exit('Access Invalid!');

class articleControl extends MobileControl
{
    public function __construct()
    {
        parent::__construct();
    }

    //文章单页
    public function indexOp()
    {
        /**
         * 根据文章编号获取文章信息
         */
        $article_model = new articleModel();
        if ($_GET['article_id']) {
            $article = $article_model->getOneArticle(intval($_GET['article_id']));
            if (empty($article) || !is_array($article) || $article['article_show'] == '0') {
                mobileJump('该文章并不存在');
            }
            Tpl::output('article', $article);
        }
        /**
         * 根据类别编号获取文章类别信息
         */
        $article_class_model = new article_classModel();
        $article_class = $article_class_model->getOneClass($article['ac_id']);
        /**
         * 类别文章列表
         */
        $article_class_model = new article_classModel();
        $child_class_list = $article_class_model->getChildClass($article_class['ac_id']);
        $ac_ids = array();
        if (!empty($child_class_list) && is_array($child_class_list)) {
            foreach ($child_class_list as $v) {
                $ac_ids[] = $v['ac_id'];
            }
        }
        $ac_ids = implode(',', $ac_ids);
        $article_model = new articleModel();
        $condition = array();
        $condition['ac_ids'] = $ac_ids;
        $condition['article_show'] = '1';
        $article_list = $article_model->getArticleList($condition);
        /**
         * 寻找上一篇与下一篇
         */
        $pre_article = $next_article = array();
        if (!empty($article_list) && is_array($article_list)) {
            $pos = 0;
            foreach ($article_list as $k => $v) {
                if ($v['article_id'] == $article['article_id']) {
                    $pos = $k;
                    break;
                }
            }
            if ($pos > 0 && is_array($article_list[$pos - 1])) {
                $pre_article = $article_list[$pos - 1];
            }
            if ($pos < count($article_list) - 1 and is_array($article_list[$pos + 1])) {
                $next_article = $article_list[$pos + 1];
            }
        }
        Tpl::output('pre_article', $pre_article);
        Tpl::output('next_article', $next_article);

        $seo_param = array();
        $seo_param['name'] = $article['article_title'];
        $seo_param['article_class'] = $article_class['ac_name'];
        Model('seo')->type('article_content')->param($seo_param)->show();
        Tpl::showpage('article_show');
    }

    //文章分类列表页
    public function article_classOp()
    {
        $art_key = trim($_GET['art_key']);
        if (!empty($art_key)) {
            $article_model = new articleModel();
            $condition['like_title'] = $art_key;
            $search_list = $article_model->getArticleList($condition);
            Tpl::output('search_list', $search_list);
        }
        //文章分类
        $article_class_model = new article_classModel();
        $class_list = $article_class_model->getClassList(1);
        $n_list = array();
        $n = 0;
        foreach ($class_list as $item) {
            if ($item['ac_parent_id'] != 0) continue;
            $n_list[$n] = $item;
            foreach ($class_list as $v) {
                if ($v['ac_parent_id'] == $item['ac_id']) {
                    $n_list[$n]['sub_class'][] = $v;
                }
            }
            $n++;
        }
        Tpl::output('list', $n_list);

        //所有文章列表
        $article_model = new articleModel();
        $condition = array();
        $condition['article_show'] = '1';
        $article_list_all = $article_model->getArticleList($condition);
        Tpl::output('article_list', $article_list_all);

        Tpl::showpage('article_class');
    }

    /*
 * 帮助中心视频列表
 * */
    public function help_videoOp()
    {
        Tpl::showpage('help_video');
    }

    /*
     * 帮助中心视频播放
     * */
    public function video_playOp()
    {
        $video_name = $_GET['video_name'];
        Tpl::output('video_name', $video_name);
        Tpl::showpage('help_video_play');
    }


    /*
     * 帮助中心卖家视频列表
     * */
    public function video_sellerOp()
    {
        Tpl::showpage('video_seller');
    }

    /*
        * 帮助中心买家/品牌视频列表
        * */
    public function video_buyerOp()
    {
        Tpl::showpage('video_buyer');
    }
}

?>
